package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.car.product.dto.request.QueryOrderDetailRequestVo;
import com.corpgovernment.api.car.product.dto.response.QueryOrderDetailResponseVo;
import com.corpgovernment.api.car.product.soa.CarProductClient;
import com.corpgovernment.api.organization.dto.request.CheckAllOrderAmountRequest;
import com.corpgovernment.common.base.JSONResult;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Slf4j
@Component
public class CarOrderClientLoader {
    @Autowired
    private CarProductClient carProductClient;


    public Map<Long, List<QueryOrderDetailResponseVo>> getCarPassengerByOrderId (List<Long> orderList) {
        QueryOrderDetailRequestVo request = new QueryOrderDetailRequestVo();
        request.setOrderList(orderList);

        JSONResult<Map<Long, List<QueryOrderDetailResponseVo>>> result = carProductClient.getCarPassengerByOrderId(request);
        if (result == null || result.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(result).map(JSONResult::getMsg).orElse("接口无响应"));
            return Maps.newHashMap();
        }
        return result.getData();

    }

    public Map<Long, List<QueryOrderDetailResponseVo>> getCarOrderAmount(CheckAllOrderAmountRequest requestVo) {
        QueryOrderDetailRequestVo request = new QueryOrderDetailRequestVo();
        request.setOrderList(requestVo.getOrderIds());
        request.setFlag(requestVo.getFlag());

        JSONResult<Map<Long, List<QueryOrderDetailResponseVo>>> result = carProductClient.getCarPassengerByOrderId(request);
        if (result == null || result.getData() == null) {
            log.error("查询支付单数据异常:" + Optional.ofNullable(result).map(JSONResult::getMsg).orElse("接口无响应"));
            return Maps.newHashMap();
        }
        return result.getData();
    }
}
